import { FormSchema } from '@apps/antd-admin/src/components/Table';
import {render} from "@apps/antd-admin/src/hooks/render/renderUtils";
import {Api } from './api';
import { RenderType } from '@pkg/setting';
export const columns = [
  {
    title: '分类名称',
    dataIndex: 'typeName',
    width: 200,
    align: 'left',
  },
  {
    title: '分类等级',
    dataIndex: 'typeCode',
    width: 50,
    customRender: ({ record }: Recordable) => {
      if(record.parentId =='2'){
        if (record.typeCode == '2') {
          return '中科院';
        }
        if (record.typeCode == '3') {
          return 'JCI';
        }
      }
      return '';
    },
  },
  {
    title: '启用',
    dataIndex: 'state',
    width: 120,
    align: 'center',
    rowKey: 'typeId',
    renderApi: Api.setState,
    customRender: render.renderSwitch,
  },
  {
    title: '排序',
    dataIndex: 'sortOrder',
    width: 50,
  }
];

const isDir = (type: string) => type === '0';
const isMenu = (type: string) => type === '1';
const isButton = (type: string) => type === '2';

export const searchFormSchema: FormSchema[] = [
  {
    field: 'typeName',
    label: '分类名称',
    component: 'Input',
    colProps: { span: 8 },
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'typeId',
    label: '分类Id',
    component: 'Input',
    required: false,
    show: false,
  },
  {
    field: 'parentId',
    label: '所属上级',
    component: 'TreeSelect',
    ifShow: ({ values }) => {
      return values.parentId != '0';
    },
    componentProps: {
      fieldNames: {
        label: 'typeName',
        key: 'parentId',
        value: 'typeId',
      },
      getPopupContainer: () => document.body,
    },
  },
  {
    field: 'typeName',
    label: '分类名称',
    component: 'Input',
    required: true,
  },

  {
    field: 'typeCode',
    label: '分类等级',
    component: 'RadioGroup',
    required: true,
    componentProps: {
      options: [
        { label: '顶级', value: '1' },
        { label: '中科院', value: '2' },
        { label: 'JCI', value: '3' },
      ],
    },
  },
  {
    field: 'sortOrder',
    label: '排序',
    component: 'InputNumber',
    required: true,
  },
];
